package cn.stronglink.assetmanage.business.patrol.view;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.sql.RowIdLifetime;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import Scaner.rfid.IRfidListener;
import Scaner.rfid.TimerRfidScaner;
import Scaner.scan.IScanerListener;
import Scaner.scan.TimerInfraraedScaner;
import cn.stronglink.assetmanage.BaseActivity;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.inventory.view.InventoryDetailActivity;
import cn.stronglink.assetmanage.business.patrol.adapter.PatrolDetailAdapter;
import cn.stronglink.assetmanage.business.search.SearchDetailsActivity;
import cn.stronglink.assetmanage.dao.DaoManager;
import cn.stronglink.assetmanage.entity.OrderType;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.entity.PatrolDetail;
import cn.stronglink.assetmanage.entity.Result;
import cn.stronglink.assetmanage.entity.Room;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.entity.User;
import cn.stronglink.assetmanage.listener.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.assetmanage.utils.LogUtil;
import cn.stronglink.assetmanage.utils.PrefUtils;
import cn.stronglink.assetmanage.utils.SpinnerShowUtil;
import cn.stronglink.assetmanage.utils.ToastUtil;
import cn.stronglink.assetmanage.utils.dao.CheckDataUtil;
import cn.stronglink.assetmanage.utils.dao.PatrolDataUtil;
import cn.stronglink.assetmanage.utils.dao.SearchDataUtil;
import cn.stronglink.assetmanage.widget.CustomProgressDialog;
import cn.stronglink.netrequest.business.patrol.PatrolService;
import okhttp3.Call;
import okhttp3.Response;

public class PatrolDetailActivity extends BaseActivity implements View.OnClickListener,
        onRecyclerListener, View.OnTouchListener, IScanerListener, IRfidListener {

    private Spinner spinner_area;
    private Button btn_patrol_detail_already;
    private Button btn_patrol_detail_wait;
    private RecyclerView rv_patrol_Detail_list;
    private TextView tv_patrol_detail_no;
    private TextView tv_patrol_detail_plant_time;
    private TextView tv_patrol_detail_num;

    private Button btn_patrol_detail_scan;
    private Button btn_patrol_detail_rfid;
    private Button btn_patrol_detail_save;
    private Button btn_patrol_detail_upload;

    private Patrol patroll; //传过来的巡检单
    private String patrolLocationName;
    //地点列表
    private List<String> areaList = new ArrayList<>();
    //全部巡检资产列表
    private List<PatrolDetail> patrolDetailList = new ArrayList<>();
    //待巡检资产列表
    private List<PatrolDetail> wait_patrolDetailList = new ArrayList<>();
    //已巡检资产列表
    private List<PatrolDetail> already_patrolDetailList = new ArrayList<>();

    private Map<String, PatrolDetail> wait_patrolDetailMap = new HashMap<>();
    private Map<String, PatrolDetail> already_patrolDetailMap = new HashMap<>();

    private List<Room> roomlist = new ArrayList<>();   //地点列表
    private String area;    //  地点名称
    private ArrayAdapter<String> arrayAdapter;   //地点适配器
    private PatrolDetailAdapter patrolDetailAdapter;
    private LinearLayoutManager layoutManager;

    private int waitNum = 0;    //未巡检的数量
    private int alreadyNum = 0;    //已巡检的数量
    private int status = 0;     //默认为待巡检

    private TimerInfraraedScaner scaner;
    private TimerRfidScaner rfidScaner;
    private float mPosX, mCurPosX;
    private Dialog mCustomProgressDialog;
    private static final String TAG = "PatrolDetailActivity";
    String patrolId;
    private Map<String, Boolean> rfidMap = new HashMap<>();
    private long lastTime, durationTime = 10 * 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patrol_detail);
        try {
            initdata();
            initview();
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
    }

    private void initview() {
        spinner_area = findViewById(R.id.spinner_patrol_detail_area);
        btn_patrol_detail_already = findViewById(R.id.btn_patrol_detail_already);
        btn_patrol_detail_wait = findViewById(R.id.btn_patrol_detail_wait);

        rv_patrol_Detail_list = findViewById(R.id.patrol_detail_asset_list);

        btn_patrol_detail_scan = findViewById(R.id.btn_patrol_detail_scan);
        btn_patrol_detail_rfid = findViewById(R.id.btn_patrol_detail_rfid);
        btn_patrol_detail_save = findViewById(R.id.btn_patrol_detail_save);
        btn_patrol_detail_upload = findViewById(R.id.btn_patrol_detail_upload);
        tv_patrol_detail_no = findViewById(R.id.tv_patrol_detail_no);
        tv_patrol_detail_num = findViewById(R.id.tv_patrol_detail_num);
        tv_patrol_detail_plant_time = findViewById(R.id.tv_patrol_detail_plant_time);


        //设置适配器
        arrayAdapter = new ArrayAdapter<>(this, R.layout.simple_spinner_item, areaList);
        spinner_area.setAdapter(arrayAdapter);

        patrolDetailAdapter = new PatrolDetailAdapter(this, null);
        layoutManager = new LinearLayoutManager(this,
                LinearLayoutManager.VERTICAL, false);
        rv_patrol_Detail_list.setLayoutManager(layoutManager);
        rv_patrol_Detail_list.setAdapter(patrolDetailAdapter);


        btn_patrol_detail_wait.setOnClickListener(this);
        btn_patrol_detail_already.setOnClickListener(this);
        btn_patrol_detail_scan.setOnClickListener(this);
        btn_patrol_detail_rfid.setOnClickListener(this);
        btn_patrol_detail_save.setOnClickListener(this);
        btn_patrol_detail_upload.setOnClickListener(this);

        tv_patrol_detail_plant_time.setText("计划执行时间");
        tv_patrol_detail_no.setText(patroll.getId_());

        //默认为待盘点选中
        btn_patrol_detail_wait.setClickable(true);
        patrolDetailAdapter.setListener(this);
        rv_patrol_Detail_list.setAdapter(patrolDetailAdapter);
        rv_patrol_Detail_list.setOnTouchListener(this);
        SpinnerShowUtil.setSpinnerItemSelectedByValue(spinner_area, patrolLocationName);
        spinner_area.setEnabled(false);

        changeColor(status);


    }

    private void initdata() {
        //获取传过来的patrolId
        Intent intent = getIntent();
        areaList.add("全部地点");
        if (intent.hasExtra("patrolDetail")) {
            patrolId = intent.getStringExtra("patrolDetail");
            if (patrolId == null) {
                ToastUtil.toastShort("巡检单号为空");
                return;
            }
            //获取当前巡检单，地点列表，资产列表
            patroll = PatrolDataUtil.getPatrolById(patrolId);

            String roomId = patroll.getRoomId_();
            patrolLocationName = PatrolDataUtil.getRoomNameByid(roomId);
            roomlist = PatrolDataUtil.getAreaList();
            String userId = User.getInstance().getId_();
            if (userId != null && !"".equals(userId)) {
                patroll.setUpdateBy(Long.valueOf(userId));
            }
            patroll.setUpdateTime(CheckDataUtil.updateTime());
            if (patroll == null || roomlist == null) {
                ToastUtil.toastShort("获取巡检单或地点为空");
                return;
            }
            if (roomlist != null) {
                for (Room room : roomlist) {
                    areaList.add(room.getName());
                }
            }
        }
    }

    private void refreshPatrolAssetData() {
        patrolDetailList = PatrolDataUtil.getPatrolDetailByOrderNo(patrolId);
        wait_patrolDetailList.clear();
        already_patrolDetailList.clear();
        if (patrolDetailList == null) {
            ToastUtil.toastShort("获取资产列表为空");
        }
        if (patrolDetailList != null) {
            for (PatrolDetail patrolDetail : patrolDetailList) {
                SearchAsset searchAsset = SearchDataUtil.getSearchAssetById_(patrolDetail.getId_());
                if (searchAsset != null) {
                    switch (patrolDetail.getStatus()) {
                        case 0:
                            wait_patrolDetailList.add(patrolDetail);
                            wait_patrolDetailMap.put(searchAsset.getRfidNo(), patrolDetail);
                            wait_patrolDetailMap.put(searchAsset.getSerialNo(), patrolDetail);
                            waitNum++;
                            break;
                        case 1:
                            already_patrolDetailList.add(patrolDetail);
                            already_patrolDetailMap.put(searchAsset.getRfidNo(), patrolDetail);
                            already_patrolDetailMap.put(searchAsset.getSerialNo(), patrolDetail);
                            alreadyNum++;
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }

    @Override
    public void onItemClicked(View v, int postion) {
        try {
            //  跳转到资产详情
            PrefUtils.putInt(PrefUtils.WHICH_SEARCH_DETAIL, 3, PatrolDetailActivity.this);
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            intent.setClass(PatrolDetailActivity.this, SearchDetailsActivity.class);
            switch (status) {
                case 0:
                    bundle.putSerializable(Constants.CHECK_IN_DETAIL_NO, wait_patrolDetailList.get(postion).getId_());
                    break;
                case 1:
                    bundle.putSerializable(Constants.CHECK_IN_DETAIL_NO, already_patrolDetailList.get(postion).getId_());
                    break;
                default:
                    break;
            }
            intent.putExtras(bundle);
            startActivity(intent);
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        try {
            setSelectPosition(3);
            refreshPatrolAssetData();
            refreshList();
            // 初始化条码扫描模块
            if (scaner == null) {
                scaner = new TimerInfraraedScaner(PatrolDetailActivity.this);
                scaner.setScanerListener(PatrolDetailActivity.this);
            }
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
    }

    private void showProgressDialog() {
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                mCustomProgressDialog = CustomProgressDialog.createLoadingDialog(PatrolDetailActivity.this,
                        "正在启动RFID扫描...");
                mCustomProgressDialog.show();
            }
        };

        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                new Handler().post(runnable);
                Looper.loop();
            }
        }.start();
    }

    //改变button的text
    private void changeText() {
        btn_patrol_detail_wait.setText("待巡检(" + waitNum + ")");
        btn_patrol_detail_already.setText("已巡检(" + alreadyNum + ")");
        tv_patrol_detail_num.setText(waitNum + alreadyNum + "");

    }

    //改变待盘点已盘点颜色
    private void changeColor(int status) {
        switch (status) {
            case 0:     //wait
                btn_patrol_detail_wait.setBackground(null);
                btn_patrol_detail_wait.setTextColor(getResources().getColor(R.color.blue_inventory_text));
                btn_patrol_detail_already.setBackgroundColor(getResources().getColor(R.color.gray_inventory_btn));
                btn_patrol_detail_already.setTextColor(Color.BLACK);
                break;
            case 1:     //already
                btn_patrol_detail_already.setBackground(null);
                btn_patrol_detail_already.setTextColor(getResources().getColor(R.color.blue_inventory_text));
                btn_patrol_detail_wait.setBackgroundColor(getResources().getColor(R.color.gray_inventory_btn));
                btn_patrol_detail_wait.setTextColor(Color.BLACK);
                break;
            default:
                break;
        }

    }

    //刷新列表
    private void refreshList() {
        List<SearchAsset> waitList = new ArrayList<>();
        List<SearchAsset> alreadyList = new ArrayList<>();

        if (area == null) {
            area = areaList.get(0);
        }
        waitNum = 0;
        alreadyNum = 0;
        if (wait_patrolDetailList != null) {
            for (PatrolDetail patrolDetail : wait_patrolDetailList) {
                if (area.equals("全部地点")) {
                    waitList.add(PatrolDataUtil.getSearchAssetById_(patrolDetail.getId_()));
                    waitNum++;
                } else if (patrolDetail.getRoomName() != null && patrolDetail.getRoomName().equals(area)) {
                    waitList.add(PatrolDataUtil.getSearchAssetById_(patrolDetail.getId_()));
                    waitNum++;
                }
            }
        }
        if (already_patrolDetailList != null) {
            for (PatrolDetail patrolDetail : already_patrolDetailList) {
                if (area.equals("全部地点")) {
                    alreadyList.add(PatrolDataUtil.getSearchAssetById_(patrolDetail.getId_()));
                    alreadyNum++;
                } else if (patrolDetail.getRoomName() != null && patrolDetail.getRoomName().equals(area)) {
                    alreadyList.add(PatrolDataUtil.getSearchAssetById_(patrolDetail.getId_()));
                    alreadyNum++;
                }
            }
        }
        patrolDetailAdapter = new PatrolDetailAdapter(this, null);
        patrolDetailAdapter.setListener(this);
        rv_patrol_Detail_list.setAdapter(patrolDetailAdapter);
        switch (status) {
            case 0:
                patrolDetailAdapter.notifyDatasChanged(waitList);
                break;
            case 1:
                patrolDetailAdapter.notifyDatasChanged(alreadyList);
                break;
            default:
                break;
        }
        changeText();

    }

    @Override
    protected void onPause() {
        super.onPause();
        try {
            if (rfidScaner.isSearching()) {
                rfidScaner.StopSearch();
                btn_patrol_detail_rfid.setBackground(getResources()
                        .getDrawable(R.drawable.bg_button_inventory_detail, null));
                btn_patrol_detail_rfid.setText("RFID扫描(OK)");

            }
            if (this.rfidScaner != null) {
                this.rfidScaner.setRfidListener(null);
                this.rfidScaner.StopSearch();
                this.rfidScaner.Destory();
                this.rfidScaner = null;
            }
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
        try {
            if (this.scaner != null) {
                this.scaner.setScanerListener(null);
                this.scaner.stop();
                this.scaner.destory();
            }
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            if (mCustomProgressDialog != null) {
                mCustomProgressDialog.cancel();
            }
            rfidMap = new HashMap<>();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 开启或关闭rfid扫描
     */
    private void switchRfidScan() {
        if (rfidScaner == null) {
            showProgressDialog();
            rfidScaner = new TimerRfidScaner(PatrolDetailActivity.this);
            rfidScaner.setRfidListener(PatrolDetailActivity.this);
            if (mCustomProgressDialog != null) {
                mCustomProgressDialog.cancel();
            }
        }
        if (rfidScaner.isSearching()) {
            rfidScaner.StopSearch();
            btn_patrol_detail_rfid.setBackground(getResources()
                    .getDrawable(R.drawable.bg_button_inventory_detail, null));
            btn_patrol_detail_rfid.setText("RFID扫描(OK)");

        } else {
            rfidScaner.StartSearch();
            btn_patrol_detail_rfid.setBackground(getResources()
                    .getDrawable(R.drawable.bg_button_inventory_detail_enter, null));
            btn_patrol_detail_rfid.setText("停止扫描");
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
        try {
            // 按下F3按钮进行Rfid扫描器的开关操作
            if (keyCode == 133) {
                this.switchRfidScan();
            }
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                onBackPressed();
            }
        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    @Override
    public boolean onKeyLongPress(int i, KeyEvent keyEvent) {
        return false;
    }

    @Override
    public boolean onKeyUp(int i, KeyEvent keyEvent) {
        return false;
    }

    @Override
    public boolean onKeyMultiple(int i, int i1, KeyEvent keyEvent) {
        return false;
    }

    /**
     * 推送扫到的Rfid到指定列表
     *
     * @param code
     */
    private void pushRfid(String code) {
        String rfid = code.replace("\r", "");
        //如果再待盘点里
        if (wait_patrolDetailMap.containsKey(rfid)) {
            // 如果扫到的rfid在巡检计划里，并且没有在已巡检到的资产列表里，就添加信息到已巡检到的列表中
            if (!already_patrolDetailMap.containsKey(rfid)) {
                PatrolDetail goods = wait_patrolDetailMap.get(rfid);
                wait_patrolDetailList.remove(goods);
                wait_patrolDetailMap.remove(rfid);
                patrolDetailList.remove(goods);
                goods.setStatus(1); // 更改资产状态为已巡检
                patrolDetailList.add(goods);
                already_patrolDetailList.add(goods);
                already_patrolDetailMap.put(rfid, goods); // 将新盘到的资产添加到已巡检列表中
                DaoManager.getDaoSession(this).getPatrolDetailDao().update(goods); // 将资产保持到数据

            } else {
                ToastUtil.getToast(this, "扫到的数据已巡检");
            }
        } else if (already_patrolDetailMap.containsKey(rfid)) {
            ToastUtil.getToast(this, "扫到的数据已巡检");
        } else {
            ToastUtil.getToast(this, "扫到的数据在库中不存在");
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                refreshList();
                lastTime = System.currentTimeMillis();

            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.btn_patrol_detail_wait:
                status = 0;
                refreshList();
                changeColor(status);
                break;
            case R.id.btn_patrol_detail_already:
                status = 1;
                refreshList();
                changeColor(status);
                break;
            case R.id.btn_patrol_detail_scan:
                try {
                    if (scaner == null) {
                        scaner = new TimerInfraraedScaner(this);
                        scaner.setScanerListener(this);
                    }
                    scaner.playSingle();
                } catch (Exception e) {
                    ToastUtil.toastShort(e.getMessage());
                }

                break;
            case R.id.btn_patrol_detail_rfid:
                switchRfidScan();
                break;
            case R.id.btn_patrol_detail_save:
                try {
                    patroll.setStatus(Constants.STATUS_THREE);
                    patroll.setOperatiorName(User.getInstance().getName());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    patroll.setUpdateTime(format.format(new Date()));
                    patroll.setDetailList(patrolDetailList);
                    PatrolDataUtil.savePatrol(patroll);
                    ToastUtil.toastShort("巡检状态更改完成");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.btn_patrol_detail_upload:
                //将状态变为已巡检
                showPatrolUploadDialog();
                break;
            default:
                break;

        }
    }

    private void showPatrolUploadDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("是否上传单中所有数据，上传成功后，本单中所有数据会删除。");
        builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                if (patroll != null) {
                    mCustomProgressDialog = CustomProgressDialog.createLoadingDialog(PatrolDetailActivity.this,
                            getString(R.string.is_upload));
                    mCustomProgressDialog.setCancelable(false);
                    mCustomProgressDialog.show();
                    patrolOrderUpload();
                }
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    private void patrolOrderUpload() {
        patroll.setDetailList(patrolDetailList);
        PatrolService patrolService = new PatrolService();
        Gson gson = new Gson();
        String data = gson.toJson(patroll);
        try {
            patrolService.uploadPatrolWorkOrder(gson.toJson(patroll), new okhttp3.Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    if (mCustomProgressDialog != null) {
                        mCustomProgressDialog.cancel();
                    }
                    ToastUtil.toastShort(patroll.getId_() + OrderType.PATROL + e.getMessage());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (mCustomProgressDialog != null) {
                        mCustomProgressDialog.cancel();
                    }
                    String json = response.body().string();
                    if (json != null) {
                        Gson gson1 = new Gson();
                        final Result<String> result = gson1.fromJson(json, new TypeToken<Result<String>>() {
                        }.getType());
                        if (result != null && result.getHttpCode() == 200) {
                            // 删除本地单子
                            ToastUtil.toastShort("上传成功");
                            PatrolDataUtil.deletePatrol(patroll);
                        } else {
                            ToastUtil.toastShort(patroll.getId_() + OrderType.PATROL + result.getMsg());
                        }
                    }

                }
            });
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {
        try {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mPosX = event.getX();
                    break;
                case MotionEvent.ACTION_MOVE:
                    mCurPosX = event.getX();
                    break;
                case MotionEvent.ACTION_UP:
                    if (mCurPosX - mPosX > 0
                            && (Math.abs(mCurPosX - mPosX) > Constants.FLUSH_DISTANCE)) {
                        //向左滑動，显示待盘点
                        if (status != 0) {
                            status = 0;
                            refreshList();
                            changeColor(status);
                        }
                        return true;
                    } else if (mCurPosX - mPosX < 0
                            && (Math.abs(mCurPosX - mPosX) > Constants.FLUSH_DISTANCE)) {
                        //向右滑动，显示已盘点
                        if (status != 1) {
                            status = 1;
                            refreshList();
                            changeColor(status);
                        }
                        return true;
                    }
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            LogUtil.e(TAG, e.getMessage());
        }
        return false;
    }

    @Override
    public void onRfiding(List<TimerRfidScaner.EpcDataBase> data) {
        try {
            if (data != null && data.size() > 0) {
                String rfid = data.get(data.size() - 1).toString().replace(" ", "");
                if (rfidMap.get(rfid) == null || !rfidMap.get(rfid)) {
                    pushRfid(rfid);
                    rfidMap.put(rfid, true);
                } else {
                    ToastUtil.getToast(PatrolDetailActivity.this, "该数据已扫描");

                }
            }
        } catch (Exception e) {
            ToastUtil.toastShort(e.getMessage());
            LogUtil.e(TAG, e.getMessage());
        }
    }

    @Override
    public void onSet() {

    }

    @Override
    public void getException(String msg) {

    }

    @Override
    public void onScaning(List<String> data) {
        try {
            if (data != null && data.size() > 0) {
                String rfid = data.get(data.size() - 1).replace(" ", "");
                pushRfid(rfid);
            }
        } catch (Exception e) {
            ToastUtil.toastShort(e.getMessage());
            LogUtil.e(TAG, e.getMessage());
        }
    }
}
